pims
provides three classes for loading video.
ImageSequence
reads images from a directory.Video
reads standard video files (AVI, MOV, etc.).TiffStack
reads multi-frame TIF / TIFF files.Once loaded, these objects can be handled alike. In software terms, each is a subclass of a generic Frames
object.
The differences between the formats are handled quietly by pims
.
Take ImageSequence
as an example. We have a folder of images here:
In [1]:
ls image_sequence
We can load them into an ImageSequence
object.
In [2]:
import pims
In [3]:
v = pims.ImageSequence('image_sequence/*.png')
We can see basic properties.
In [4]:
v
Out[4]:
We can print the first frame (it's an array of brightness values) or view those values as an image.
In [6]:
print v[0]
In [7]:
%matplotlib inline
v[0]
Out[7]:
In [ ]:
for frame in v[:]:
# Do something with frame, a numpy array.
ImageSequence
relies only on numpy
and scipy
, which are required dependencies of mr
, so it works
out of the box. Video
needs OpenCV, which includes the Python module cv2
.
TiffStack
needs libtiff
.
Once these dependencies are in place, Video
and TiffStack
work in the same way as ImageSequence
.
In [14]:
v = pims.Video('/home/dallan/mr/mr/tests/water/bulk-water.mov')
# This file is not included in PIMS, to keep the file size small.
# Try it with a video file of your own.
In [15]:
v
Out[15]:
In [8]:
v = pims.TiffStack('tiff_stack.tif')
In [9]:
v
Out[9]: